﻿using System;
using _5E.WebInfrastructure.Security;
using StoneAge.Infrastructure.Configuration;

namespace StoneAge.Controller.User
{
    public class UserCookie
    {
        private DateTime m_lastModiftDate = DateTime.Now;

        private string m_LoginName = null;
        public string LoginName
        {
            get { return m_LoginName; }
            set { m_LoginName = value; }
        }

        private Guid m_AccountId = Guid.Empty;
        public Guid AccountId
        {
            get { return m_AccountId; }
            set { m_AccountId = value; }
        }

        private Guid m_RoleId = Guid.Empty;
        public Guid RoleId
        {
            get { return m_RoleId; }
            set { m_RoleId = value; }
        }

        public void Save()
        {
            CustomFormsAuthentication<UserCookie>.SignIn(LoginName, this, ApplicationSettingsFactory.ApplicationSettings.SessionValidTime);
        }

        public void Update()
        {
            if (ApplicationSettingsFactory.ApplicationSettings.SaveRoleTick < (DateTime.Now - m_lastModiftDate).TotalMinutes)
            {
                m_lastModiftDate = DateTime.Now;
                Save();
            }
        }
    }
}
